package vm

const harvesterUrl = "https://192.168.0.202:30443"

type DataVolume struct {
	Name             string `json:"name"`
	Namespace        string `json:"namespace"`
	Phase            string `json:"phase"`
	Progress         string `json:"progress"`
	Url              string `json:"url"`
	StorageClassName string `json:"storageclassname"`
	Storage          string `json:"storage"`
	VolumeMode       string `json:"volumemode"`
}

type DataVolumeResponse struct {
	Kind  string       `json:"kind"`
	Items []DataVolume `json:"items"`
}

//type ListDataVolumeResponse struct {
//	status  string
//	message DataVolumeStatus
//}

type PVCEvents struct {
	Name           string  `json:"name"`
	Namespace      string  `json:"namespace"`
	Kind           string  `json:"kind"`
	Reason         string  `json:"reason"`
	FirstTimestamp string  `json:"firstTimestamp"`
	LastTimestamp  string  `json:"lastTimestamp"`
	Type           string  `json:"type"`
	Count          float64 `json:"count"`
	Message        string  `json:"message"`
}

type HostInfo struct {
	HostName  string `json:"hostname"`
	IpAddress string `json:"ipaddress"`
}

type HostInfoResponse struct {
	Kind  string     `json:"kind"`
	Items []HostInfo `json:"items"`
}

type PVCEventsResponse struct {
	Kind  string      `json:"kind"`
	Items []PVCEvents `json:"items"`
}

type ResizingPVCResponse struct {
	Kind          string      `json:"kind"`
	ResizedItems  []PVCEvents `json:"resizedItems"`
	ResizingItems []PVCEvents `json:"resizingItems"`
	SuccessItems  []PVCEvents `json:"successItems"`
}

type HarvesterApiRequest struct {
	APIName    string `json:"api_name"`
	MethodType string `json:"method_type"`
	Params     string `json:"params"`
}

type MinioLoginRequest struct {
	AccessKey string `json:"access_key"`
	SecretKey string `json:"secret_key"`
	Url       string `json:"url"`
}

type DataVolumeTemplate struct {
	Spec       *Spec     `yaml:"spec"`
	ApiVersion string    `yaml:"apiVersion"`
	Kind       string    `yaml:"kind"`
	Metadata   *Metadata `yaml:"metadata"`
}

type Resources struct {
	Requests *Requests `yaml:"requests"`
}

type Requests struct {
	Storage string `yaml:"storage"`
}

type Source struct {
	Http *Http `yaml:"http"`
}

type Http struct {
	Url string `yaml:"url"`
}

type Metadata struct {
	Name      string `yaml:"name"`
	Namespace string `yaml:"namespace"`
}

type Spec struct {
	Pvc    *Pvc    `yaml:"pvc"`
	Source *Source `yaml:"source"`
}

type Pvc struct {
	VolumeMode       string     `yaml:"volumeMode"`
	StorageClassName string     `yaml:"storageClassName"`
	Resources        *Resources `yaml:"resources"`
	AccessModes      []string   `yaml:"accessModes"`
}

type RemoteClient struct {
	RemoteAddress  string `json:"remoteAddress"`
	RemoteUsername string `json:"remoteUsername"`
	RemotePassword string `json:"remotePassword"`
}

func getDataVolumeTemplate(name string, namespace string, url string, storage string, storageclass string) *DataVolumeTemplate {
	dvTemplate := &DataVolumeTemplate{
		Spec: &Spec{
			Pvc: &Pvc{
				VolumeMode:       "Block",
				StorageClassName: storageclass,
				Resources:        &Resources{Requests: &Requests{Storage: storage}},
				AccessModes:      []string{"ReadWriteMany"},
			},
			Source: &Source{Http: &Http{Url: url}},
		},
		ApiVersion: "cdi.kubevirt.io/v1beta1",
		Kind:       "DataVolume",
		Metadata: &Metadata{
			Name:      name,
			Namespace: namespace,
		},
	}
	return dvTemplate
}
